#include "NxServiceAPI.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <Windows.h>

int main()
{
	const char* version = NJGIS::SERVICE::getVersion();
	std::cout << version <<std::endl;
	NJGIS::SERVICE::INjServerFactory* pServerFactory = NJGIS::SERVICE::createServerFactory();
	NJGIS::SERVICE::INjServer* pServer = pServerFactory->createServer("127.0.0.1");
	if(pServer != NULL)
	{
		if(pServer->connect() == 1)
		{
			std::cout <<"Hello My SDK!" << std::endl;
			NJGIS::SERVICE::INjServiceAccess* pServiceAccess = pServer->getServiceAccess();
			std::vector<NJGIS::SERVICE::INjModelService*> list_ms;
			pServiceAccess->getModelServicesList(list_ms);
			
			for(int i = 0; i < list_ms.size(); i++)
			{
				if(list_ms[i] == NULL) continue;
				std::cout << list_ms[i]->getServiceOID() << " - " << list_ms[i]->getServiceName() << " - " << list_ms[i]->getServiceType() << std::endl;
			}
			// upload data
			NJGIS::SERVICE::INjData* pData = pServiceAccess->getDataServiceByID("gd_b3f13f70-4891-11e8-b000-3571b206c6be");
			pData->saveAs("E:\\DemoData\\GeoModeling\\udx_zip_d8\\tmp.zip");

			
			//if(pData != NULL)
			//{
			//	std::cout << pData->getID() << " - " << pData->getSize() << " - " << pData->getGenarationDateTime() << " - " << pData->getTag() << std::endl;
			//	NJGIS::SERVICE::INjModelService* pMservice = pServiceAccess->getModelServiceByOID("5ac9dbcdbe7b8d12c484952e");
			//	NJGIS::SERVICE::INjDataConfiguration * pDataconfig = pServiceAccess->createDataConfig();
			//	pDataconfig->insertData("04579ee0-5983-4d75-bdc9-a1a460229aa0","LoadHydroResponseUnit",pData->getID());
			//	std::string recordid;
			//	// invoke model service
			//	if(pMservice->invoke(pDataconfig, recordid) == 1 )
			//	{
			//		std::cout << "Invoke successfully! Model Service Record ID is : [" << recordid << "]" << std::endl;
			//		NJGIS::SERVICE::INjModelServiceRecord* pRecord = pServiceAccess->getModelServiceRecordByID(recordid.c_str());
			//		NJGIS::SERVICE::INjModelServiceInstance* pInstance = pServiceAccess->getModelServiceInstanceByGUID(pRecord->getGUID());
			//		pInstance->wait4Status(NJGIS::SERVICE::NjModelInstanceStatus::INSTA_FINISHED, 7200, true);
			//	}
			//}
		}
	}

	return 1;
}